
import Flexbox from 'vux/src/components/flexbox/flexbox.vue'
import FlexboxItem from 'vux/src/components/flexbox/flexbox-item.vue'
import XButton from 'vux/src/components/x-button/index.vue'
import XHeader from 'vux/src/components/x-header/index.vue'
import Actionsheet from 'vux/src/components/actionsheet/index.vue'
import Popup from 'vux/src/components/popup/index.vue'
import TransferDom from 'vux/src/directives/transfer-dom/index'
import Group from 'vux/src/components/group/index.vue'
import Cell from 'vux/src/components/cell/index.vue'
import Checker from 'vux/src/components/checker/checker.vue'
import CheckerItem from 'vux/src/components/checker/checker-item.vue'
import XInput from 'vux/src/components/x-input/index.vue'
import Alert from 'vux/src/components/alert/index.vue'
import VueQr from 'vue-qr'
import confirm from 'vux/src/components/confirm/index.vue'

import CONSTANT from '@/common/constants.js'
import http from '@/common/http.js'
export default {
  name: 'homedonation',
  components: {
    Flexbox, FlexboxItem, XHeader, XButton, Actionsheet, Popup, Group, Cell, Checker, CheckerItem, XInput, Alert, VueQr,
    confirm
  },
  directives: {
    TransferDom
  },
  data () {
    return {
      menus: {
        menu1: '邀请您的朋友一起捐'
      },
      showf: false,
      showj: false,
      together_id: '',
      demo: 10,
      checkOK: true,
      textMoney: '',
      userId: '',
      ifselected: false,
      qrcodeImg: '',
      showAlert: false,
      titleAlert: '扫描下方二维码',
      logoSrc: this.imageUrl.imageUrl+'/userfiles/2/images/1513911875.png',
      dotScale: 1,
      margin: 0,
      logoMargin: 5,
      logoCornerRadius: 4,
      showConfirm:false,
      obj: {
        eventName: '',
        eventPicUrl: '',
        headUrl: '',
        name: '',
        raiseMoney: '',
        event_id: '',
        content: ''
      }
    }
  },
  mounted () {
    this.together_id = this.$route.query.together_id
    let openid = sessionStorage.getItem("openid")
    if (openid == null || openid == '' || openid == 'undefined') {
      sessionStorage.setItem('openid', this.$route.query.openId)
      sessionStorage.setItem('userId', this.$route.query.userId)
      sessionStorage.setItem('wxAvatar', this.$route.query.wxAvatar)
      sessionStorage.setItem('nickName', this.$route.query.nickName)
      let openid = sessionStorage.getItem("openid")
      if (openid == null || openid == '' || openid == 'undefined') {
        alert('进行页面的跳转')
        window.location.href = 'http://www.qqchou.org/a/wxinterface/wxOAuth?category=1&together_id=' + this.together_id
      }
    }
    if (this.$emit('ifOpenid')) {
      this.$emit('ifOpenid', this.$route.path, this.together_id)
    }
    if (this.$route.query.openId) {
      window.history.go(0)
    }
    http.post(CONSTANT.TOGETHER_DETAIL, {together_id: this.together_id}, (res) => {
      console.log(res)
      if (res.code == 200) {
        this.obj = res.obj
        if (this.obj.eventStatus == 1 && parseFloat(this.obj.raiseMoney) < this.obj.eventGoalAmount) {
          this.showConfirm = true
        }
        this.$nextTick(() => {
          this.$refs.donationFoot.style.display = 'block'
        })
        // alert('项目id*****' + this.obj.event_id)
      }
      if (this.$emit('ShareAppMessage')) {
        if (this.obj.mingcheng != '') {
          var title = this.obj.name+'发起的【'+this.obj.mingcheng+'】邀请您助力'+this.obj.eventName;
          this.$emit('ShareAppMessage', title, '我为' + this.obj.eventName + '发起筹款，为一个善意而美好的世界，大家\'益\'起来', 'http://www.qqchou.org/a/wxinterface/wxOAuth?category=1&together_id=' + this.together_id, this.imageUrl.imageUrl + this.obj.eventPicUrl)
        } else {
          this.$emit('ShareAppMessage', this.obj.eventName, '我为' + this.obj.eventName + '发起筹款，为一个善意而美好的世界，大家\'益\'起来', 'http://www.qqchou.org/a/wxinterface/wxOAuth?category=1&together_id=' + this.together_id, this.imageUrl.imageUrl + this.obj.eventPicUrl)
        }
      }
      this.qrcodeImg = 'http://www.qqchou.org/a/wxinterface/wxOAuth?category=1&together_id=' + this.together_id
    })
    // this.together_id = window.sessionStorage.getItem('together_id')
    // this.userId = window.sessionStorage.getItem('userId')
  },
  methods: {
    onHide () {
      console.log('on hide')
    },
    onShow () {
      console.log('on show')
    },
    // GetRequest () {
    //   // var url = window.location.search // 获取url中"?"符后的字串
    //   var aurl = window.location.href
    //   // console.log('完整的url*****' + aurl)
    //   var arr = aurl.split('/homedonation')
    //   var url = arr[1]
    //   var theRequest = new Object()
    //   if (url.indexOf('?') != -1) {
    //     var str = url.substr(1)
    //     let strs = str.split('&')
    //     for (var i = 0; i < strs.length; i++) {
    //       theRequest[strs[i].split('=')[0]] = encodeURIComponent(strs[i].split('=')[1])
    //     }
    //     this.together_id = theRequest['together_id']
    //     http.post(CONSTANT.TOGETHER_DETAIL, {together_id: this.together_id}, (res) => {
    //       console.log(res)
    //       if (res.code == 200) {
    //         this.obj = res.obj
    //       }
    //     })
    //     console.log(theRequest)
    //   }
    // },
    primary () {
      let num = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
      let _this = this
      if (_this.demo == '') {
        alert('请选择捐款金额!')
      } else if (!num.test(_this.demo)) {
        alert('请输入正确的金额数!（提示：只能是数字或者精确到两位小数）')
      } else if (_this.demo == 0 || _this.demo == '0.00') {
        alert('请输入正确的金额数!（提示：只能是数字或者精确到两位小数）')
      } else if (this.checkOK == false) {
        alert('请同意并接受\n《亲青筹用户协议》！')
      } else {
        // window.location.href = 'http://www.qqchou.org/a/wxinterface/payment?' + 'witchOne=geren&userId=' +
        //   this.userId + '&money=' + this.demo + '&eventId=' + this.event_id
        this.$router.push({path: '/payment', query: {witchOne: 'geren', money: this.demo, together_id: this.together_id,event_id:this.obj.event_id}})
      }
    },
    keyups () {
      this.demo = this.textMoney
      this.ifselected = true
    },
    blurs () {
      this.ifselected = false
    },
    isShow () {
      // 弹出框关闭按钮
      this.showj = false
    },
    primaryshow () {
      this.showj = true
    },
    finishInvitation () {
      // 点击完成邀请按钮触发
      this.showf = true
    },
    comeback () {
      // 点击返回编辑时触发
      // window.history.go(-1)
      // this.$router.push({path: '/donation', query: {content: this.$route.query.content}})
    },
    goProject () {
      // 点击查看详情时触发
      this.$router.push({path: '/Project', query: {'event_id': this.obj.event_id}})
    },
    togetherRecord () {
      this.$router.push({path: '/togetherRecord', query: {'event_id': this.obj.event_id,'together_id':this.together_id}})
    },
    onCancel(){

    },
    onConfirm() {
        this.primaryshow()
    },
    onShow() {

    },
    onShow() {

    }
  }
}
